package com.facebook.android;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Timer;
import java.util.TimerTask;

import com.facebook.android.Facebook.DialogListener;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;



public class SplashActivity extends Activity {
    private long splashDelay = 1500;
    
    Facebook facebook = new Facebook("390944314260651");

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        try {
            PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md;

                    md = MessageDigest.getInstance("SHA");
                    md.update(signature.toByteArray());
                    String something = new String(Base64.encode(md.digest(), 0));
                    Log.e("hash key", something);
            } 
        } catch (NameNotFoundException e1) {            
            Log.e("name not found", e1.toString());
        } catch (NoSuchAlgorithmException e) {
                 Log.e("no such an algorithm", e.toString());
         }catch (Exception e){
                 Log.e("exception", e.toString());
         }

        
        facebook.authorize(this, new String[] { "read_stream", "user_likes" },

      	      new DialogListener() {
      	           @Override
      	           public void onComplete(Bundle values) {}

      	           @Override
      	           public void onFacebookError(FacebookError error) {}

      	           @Override
      	           public void onError(DialogError e) {}

      	           @Override
      	           public void onCancel() {}
      	      }
      	);
      
        setContentView(R.layout.main);
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                finish();
                Intent hackbookIntent = new Intent().setClass(SplashActivity.this, Hackbook.class);
                startActivity(hackbookIntent);
            }
        };

        Timer timer = new Timer();
        timer.schedule(task, splashDelay);
    }
    
 
    /*
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        facebook.authorizeCallback(requestCode, resultCode, data);
    }
    */
    
    
}
